package com.example.apiversioncontroldemo.config;

import com.example.apiversioncontroldemo.util.vcon.IllegalApiVersionException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chen.cr
 * @since 2023/11/1
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(IllegalApiVersionException.class)
    public ResponseEntity<?> handleExp(IllegalApiVersionException ex, HttpServletRequest request) {
        log.error("请求地址：{}", request.getRequestURI(), ex);
        return new ResponseEntity<>(ex.getMessage(), new HttpHeaders(), 499);
    }

}
